// pages/my/my-index/beanPage.js
const controller=require("../../controllers/Controller").controller
const payAndInput=require("../../controllers/ControllerVip").controller.payAndInput;


const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNumber:1,
    amountList:'',
    lastPage:false,
    selectIndex:0
  },

  //切换tab
  changeTab(e){
    this.setData({
      selectIndex:e.currentTarget.dataset.index
    })
    if(this.data.selectIndex==0){
      this.getBeanPage()
    }else{
      this.getCashOutHistory()
    }
  },

  //获取提现记录
  getCashOutHistory(){
    let value={}
    value.type=1
    value.pageNumber=this.data.pageNumber
    value.shopId=wx.getStorageSync('shopId')
    controller.getCashHistory(value).then(res=>{
      this.setData({
        amountList:res.data.list,
        lastPage:res.data.lastPage
      })
    })
  },


  //跳转提现
  toCashOut(){
    wx.navigateTo({
      url: '/pages/my/vip/vip_renew/index?type=cashOut',
    })
  },

  //获取积分余额
  getPayAndInput(){
    let value={
      amountType:1,
      shopId:app.globalData.shopId
    }
    payAndInput(value).then(res=>{
      this.setData({
        moneyData:res.data
      })
    })
  },

  //获取金币账单
  getBeanPage(){
    let value={}
    value.pageNumber=this.data.pageNumber
    value.shopId=wx.getStorageSync('shopId')
    value.accountId=wx.getStorageSync('accountId')
    controller.beanPage(value).then(res=>{
      this.setData({
        amountList:res.data.list,
        lastPage:res.data.lastPage
      })
    })
  },

  getMore(){
    if(this.data.lastPage==false){
      if(this.data.selectIndex==0){
        let value={}
        value.pageNumber=this.data.pageNumber
        value.shopId=wx.getStorageSync('shopId')
    
        controller.beanPage(value).then(res=>{
          let list=this.data.amountList
          let list2=res.data.list
          let list3=list.concat(list2)
          this.setData({
            amountList:list3,
            lastPage:res.data.lastPage
          })
        })
      }else{
        let value={}
        value.pageNumber=this.data.pageNumber
        value.type=1
    
        controller.getCashHistory(value).then(res=>{
          let list=this.data.amountList
          let list2=res.data.list
          let list3=list.concat(list2)
          this.setData({
            amountList:list3,
            lastPage:res.data.lastPage
          })
        })
      }
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBeanPage()
    this.getPayAndInput()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getMore()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})